home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0018_Variable Number Parameter.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  68 lines

  1. {
  2. |│-> You can allocate some memory and put all your parameters there, then
  3. |│-> pass a pointer which points to this memory block.  You have to
  4. |│-> setup some convention if you want to pass different types, or
  5. |│-> parameters with different length.
  6. |│
  7. |│Well how do I do that in Pascal- I really think that I might be better
  8. |│off making the function in C and then compiling it out to an object file
  9. |│and then linking it into pascal
  10.  
  11. Mixed language programming is tricky and difficult unless the
  12. compilers explicitely support it.
  13.  
  14. |│but I am not sure that that will even
  15. |│work I might just abandon Pascal and learn C
  16.  
  17. Good luck!  <evil grin>
  18.  
  19. |│(even though the SYNTAX rules for C are based on Pascal anyhow)
  20.                                           ^^^^^^^^^^^^^^^
  21. Hmmmm.....
  22.  
  23. Anyway, here's a quick and dirty example (untested) about passing
  24. pointers and variable # of parameters.
  25. }
  26. PROGRAM Pass_Pointer;     {Compiled with TP _3.01A_}
  27.  
  28. TYPE
  29.    Short_String = STRING[15];
  30.  
  31. CONST
  32.    max_count  = 13;
  33.    terminator : Short_String = #0#0#0#0#0#0#0#0#0#0#0#0#0#0#0;
  34.  
  35. TYPE
  36.    String_Array = ARRAY [0..max_count] OF Short_String;
  37.    Pointer = ^String_Array;
  38.  
  39. VAR
  40.    star : Pointer;
  41.    sstr : Short_String;
  42.    count, i : INTEGER;
  43.  
  44. PROCEDURE Receiver (P : pointer);
  45. BEGIN
  46.    i := 0;
  47.    WHILE (P^[i] <> terminator) AND (i < max_count) DO BEGIN
  48.       writeln(P^[i]);
  49.       i := i + 1;
  50.    END;
  51. END;
  52.  
  53. BEGIN
  54.    count := 0;
  55.    New (star);
  56.    REPEAT
  57.       write('Enter a short string: ');
  58.       readln(sstr);
  59.       star^[count] := sstr;
  60.       count := count + 1;
  61.    UNTIL (sstr = '') OR (count >= max_count);
  62.  
  63.    IF count < max_count THEN
  64.       star^[count - 1] := terminator;
  65.  
  66.    Receiver(star);
  67. END.
  68.